//
//  QSSignSuccessViewController.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/27.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSSignSuccessViewController.h"
#import "QSMainTabBarController.h"
#import "QSAddVisitViewController.h"
#import "QSSendProblemViewController.h"
@interface QSSignSuccessViewController ()
/** 已完成图片*/
@property (nonatomic, strong)UIImageView *successImageView;
/** 已完成Label*/
@property (nonatomic, strong)UILabel *successLabel;
/** 返回首页按钮*/
@property (nonatomic, strong)UIButton *backHomeButton;
/** 添加走访记录按钮*/
@property (nonatomic, strong)UIButton *addVisitRecordButton;
/** 提交企业记录按钮*/
@property (nonatomic, strong)UIButton *sendEnterpriseButton;

@end

@implementation QSSignSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"驻企签到";
    [self configSubView];
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ic_navigation_back"] target:self action:@selector(backHomeAction:)];
    
    self.navigationItem.leftBarButtonItem = backBtn;
}

- (void)configSubView{
    [self.view addSubview:self.successImageView];
    [self.view addSubview:self.successLabel];
    [self.view addSubview:self.backHomeButton];
    [self.view addSubview:self.addVisitRecordButton];
    [self.view addSubview:self.sendEnterpriseButton];
    
    [_successImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(kRealValue(57));
        make.width.offset(kRealValue(136));
        make.height.offset(kRealValue(128));
    }];
    [_successLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_successImageView.mas_bottom).offset(kRealValue(18));
    }];
    [_backHomeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(kRealValue(65));
        make.right.equalTo(self.view).offset(- kRealValue(65));
        make.top.equalTo(_successLabel.mas_bottom).offset(kRealValue(78));
        make.height.offset(kRealValue(44));
    }];
    [_sendEnterpriseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(kRealValue(65));
        make.right.equalTo(self.view).offset(- kRealValue(65));
        make.bottom.equalTo(self.view).offset(- kRealValue(100));
        make.height.offset(kRealValue(44));
    }];
    [_addVisitRecordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(kRealValue(65));
        make.right.equalTo(self.view).offset(- kRealValue(65));
        make.bottom.equalTo(self.sendEnterpriseButton.mas_top).offset(- kRealValue(19));
        make.height.offset(kRealValue(44));
    }];
}

- (UIImageView *)successImageView{
    if (!_successImageView) {
        _successImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_signSuccess"]];
    }
    return _successImageView;
}

- (UILabel *)successLabel{
    if (!_successLabel) {
        _successLabel = [UILabel labelWithName:@"您已完成签到!" font:[UIFont QSFontOfSize16] textColor:[UIColor QSColorBlack666666] textAlignment:NSTextAlignmentCenter];
    }
    return _successLabel;
}

- (UIButton *)backHomeButton{
    if (!_backHomeButton) {
        _backHomeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _backHomeButton.backgroundColor = [UIColor colorWithHexString:@"#128BEC"];
        [_backHomeButton setTitleColor:[UIColor QSColorWhiteFFFFFF] forState:UIControlStateNormal];
        [_backHomeButton setTitle:@"返回首页" forState:UIControlStateNormal];
        [_backHomeButton.titleLabel setFont:[UIFont QSFontOfSize16]];
        _backHomeButton.layer.cornerRadius = 22;
        [_backHomeButton addTarget:self action:@selector(backHomeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _backHomeButton;
}

- (UIButton *)addVisitRecordButton{
    if (!_addVisitRecordButton) {
        _addVisitRecordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addVisitRecordButton.backgroundColor = [UIColor QSColorWhiteFFFFFF];
        [_addVisitRecordButton setTitleColor:[UIColor colorWithHexString:@"#128BEC"]     forState:UIControlStateNormal];
        [_addVisitRecordButton setTitle:@"添加走访记录" forState:UIControlStateNormal];
        [_addVisitRecordButton.titleLabel setFont:[UIFont QSFontOfSize16]];
        
        _addVisitRecordButton.layer.cornerRadius = 22;
        _addVisitRecordButton.layer.borderColor = [UIColor colorWithHexString:@"#128BEC"].CGColor;
        _addVisitRecordButton.layer.borderWidth = 0.5f;
        [_addVisitRecordButton addTarget:self action:@selector(addVisitRecordAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _addVisitRecordButton;
}

- (UIButton *)sendEnterpriseButton{
    if (!_sendEnterpriseButton) {
        _sendEnterpriseButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _sendEnterpriseButton.backgroundColor = [UIColor QSColorWhiteFFFFFF];
        [_sendEnterpriseButton setTitleColor:[UIColor colorWithHexString:@"#2963CF"]     forState:UIControlStateNormal];
        [_sendEnterpriseButton setTitle:@"添加企业问题" forState:UIControlStateNormal];
        [_sendEnterpriseButton.titleLabel setFont:[UIFont QSFontOfSize16]];
        
        _sendEnterpriseButton.layer.cornerRadius = 22;
        _sendEnterpriseButton.layer.borderColor = [UIColor colorWithHexString:@"#2963CF"].CGColor;
        _sendEnterpriseButton.layer.borderWidth = 0.5f;
        [_sendEnterpriseButton addTarget:self action:@selector(sendEnterpriseAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _sendEnterpriseButton;
}

- (void)backHomeAction:(UIButton *)sender{
    if ([[UIViewController currentViewController] isKindOfClass:NSClassFromString(@"QSMainTabBarController")]) {
        return;
    }
    
    [UIApplication sharedApplication].keyWindow.rootViewController = [[QSMainTabBarController alloc] init];
}

- (void)addVisitRecordAction:(UIButton *)sender{
    QSAddVisitViewController *vc = [QSAddVisitViewController new];
    vc.companyKey = self.companyKey;
    vc.companyName = self.companyName;
    vc.evSignId = self.signId;//在签到成功新增走访传signId
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)sendEnterpriseAction:(UIButton *)sender{
    QSSendProblemViewController *vc = [QSSendProblemViewController new];
    vc.companyKey = self.companyKey;
    vc.companyName = self.companyName;
    vc.signId = self.signId;
    vc.townshipId = self.townshipId;
    vc.townshipName = self.townshipName;
    [self.navigationController pushViewController:vc animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
